
export const baseUrl = 'http://39.107.118.71:8012';

import {wxOpenid,checkLogin} from '@/utils/login-sdk.js'



export async function request(params) {
	let { url,data,method,token } = params
	const wxUser = uni.getStorageSync('wxuser')
	return new Promise((reslove, reject) => {
		uni.request({
			url: baseUrl + url,
			data,
			method,
			header: {
				'Content-Type':'application/json',
				'jwt':wxUser.jwt,
				'idempotenceToken':token
			},
			success: (res) => {
				if(res.data.code == 200){
					 reslove(res.data)
				}else if(res.data.code==300){
					reject(res)
					uni.showModal({
						title:"提示",
						content:res.data.msg || "服务错误",
						showCancel:false,
						success: (ret) => {
							uni.reLaunch({
								url:'/pages/login/login'
							})
						}
					})
				}else{
					reject(res)
					uni.showModal({
						title:"提示",
						content:res.data.msg || "服务错误",
						showCancel:false,
					})
				}
			},
			fail: (ret) => {
				reject(ret)
			},
			complete: function() {
				uni.hideLoading();
			}
		});
	})
}

/** 文件上传 */
export const uploadFile = (params)=>{
	// const {filePath} = params
	const wxUser = uni.getStorageSync('wxuser')
	return new Promise((resolve,reject)=>{
		uni.uploadFile({
			url:baseUrl+"/xcx/file/oss/upload",
			filePath:params,
			name:"file",
			header:{
				'jwt':wxUser.jwt
			},
			success: (ret) => {
				resolve(ret)
			}
		})
	})
	
}